JD Long
2018-10-26
* I am sharing my personal views not the views of RenaissanceRe Holdings, Ltd. or any of its subsidiary companies.
* Thought provoking only: The materials are provided for information purposes only, are in summary form, and thus do not include all information necessary for analysis.
* This is not consulting: No representations or warranties are give as to the accuracy or completeness of the materials and no professional advice or guidance is given by the presentation. If you want to use these ideas, professional consultation should be sought.
* This is not financial advice: No financial advice is being given nor any recommendation to invest in any financial product. Historical data is no assurance as to future results.
All data, code, and examples: CerebralMastication/Presentations
Take Pix, Dance, Ask, Tweet @cmastication
– Obligatory XKCD
– Key Point: R Fits into Corporate Reporting
– R in Corporate Reporting Fits Better if You're Not an Asshole (empathy!)
– 3 Easy Tricks to Try Tonight to Make Your Reporting Hotter
Stack Overflow…
– All time is of equal value and is interchangeable
– All time is of equal value and is interchangeable
– Current frequency of reporting = future freq
– All time is of equal value and is interchangeable
– Current frequency of reporting = future freq
– All activities are of equal utility (nothing sucks your will to live!)
– All time is of equal value and is interchangeable
– Current frequency of reporting = future freq
– All activities are of equal utility (nothing sucks your will to live!)
– Automated and manual workflows produce the same product (errors?)
It looks like you're doing a data science!
Would you like me to format your integers as dates?!?
– Use R Studio Project structure (or here package)
– Use R Studio Project structure (or here package)
– Keep all files in sub directories in relative paths
– Use R Studio Project structure (or here package)
– Keep all files in sub directories in relative paths
– Naming convention - make it sort right
– Use R Studio Project structure (or here package)
– Keep all files in sub directories in relative paths
– Naming convention - make it sort right
– Sub Directories: make it easy to grok
– Use R Studio Projects (or here package)
– Keep all files in relative paths
– Naming convention: sorting
– Sub Directories: easy to grok
– Passwords in environ variables
– Markdown File (*.Rmd) - minimal
– Sourced R script (*.R) - most here
– Package: if used more than 2 times
– Params - Knitr YAML - For easy maintenance
– Worded package by David Gohel - Page Breaks and page orientation hacks
– Flextable package by David Gohel - Table formatting controls
– Officer package by (guess who?) David Gohel! - more table formatting
---
title: "My Amazing Report"
output:
worded::rdocx_document:
reference_docx: 10_amazing_report_template.docx
toc: false
toc_depth: 2
date: '2018-10-26'
params:
main: 'mycompany 2018-10-01'
compare: 'mycompany 2018-07-01'
---
```{r, include=FALSE}
library(flextable)
library(our_kickass_corp_package)
my_corp_db_con <-
our_db_connect(Sys.getenv('MYUID'),
Sys.getenv('MYPWD'))
regulartable(my_cars) %>%
color(i = 1, color = "#003e51", part = "header") %>%
autofit %>%
theme_zebra(odd_header = "transparent",
even_header = "transparent") %>%
fontsize(size = 9, part = 'all') %>%
border_outer(
border = officer::fp_border(color = "gray70",
width = 2),
part = "all") %>%
align(align = "center", part = 'header') %>%
align(j = 1, align = "right", part = 'body') %>%
align(j = 2:4, align = "center", part = 'body') %>%
set_formatter(
`mpg` = function(x)
formatC(x,
digits = 1,
format = "f",
big.mark = ","),
)
```{r, echo=FALSE, dpi=300, fig.width=5, fig.height=2.9}
```{r, echo=FALSE}
my_groups <- unique(mtcars$cyl)
out <- list()
for (group in my_groups){
out = c(out, knitr::knit_child('10_sub.Rmd'))
}
Children are evaluated in the context (namespace etc.) of the parent
`r paste(out, collapse='\n')`
library(openxlsx)
xlfile <- 'my_junk.xlsx'
wb <- loadWorkbook(xlfile)
removeTable(wb=wb, sheet='Sheet1', table="our_table")
writeDataTable(
wb, sheet='Sheet1', x=my_df,
tableName="our_table",
startCol=3, startRow=10
)
saveWorkbook(wb=wb, file=xlfile,
overwrite = TRUE)